package com.isias.system.Controller;

import com.isias.common.result.Result;
import com.isias.model.system.SysDept;
import com.isias.model.system.SysDept;
import com.isias.model.system.SysMenu;
import com.isias.model.vo.AssginMenuVo;
import com.isias.system.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学科班级表
 * @author fanyi
 */
@RestController
@RequestMapping("/admin/system/sysDept")
public class SysDeptController {
    @Autowired
    SysDeptService service;
    
    /***
     * 查询(树结构)
     */
    @GetMapping
    public Result SelectPage(){
        List<SysDept> list = service.findNodes();
        if (list!=null){
            return Result.ok(list);
        }
        return Result.fail();
    }
    /***
     * 增加
     */
    @PostMapping
    public Result AddMenu(@RequestBody SysDept sysDept){
        if (service.save(sysDept)) {
            return Result.ok();
        }
        return Result.fail();
    }
    /***
     * 修改
     */
    @PutMapping
    public Result UpdataMenu(@RequestBody SysDept sysDept){
        if (service.updateById(sysDept)) {
            return Result.ok();
        }
        return Result.fail();
    }
    /***
     * 删除
     */
    @DeleteMapping("{id}")
    public Result DeleteMenu(@PathVariable String id){
        if (service.removeDeptById(id)) {
            return Result.ok();
        }
        return Result.fail();
    }
    /***
     * 根据id查询
     */
    @GetMapping("{id}")
    public Result SelectById(@PathVariable String id){
        SysDept sysDept = service.getById(id);
        if (sysDept!=null){
            return Result.ok(sysDept);
        }
        return Result.fail(null);
    }

    /***
     * 根据用户获取班级（树形结构）
     */
    @GetMapping("/toAssign/{userId}")
    public Result toAssign(@PathVariable String userId) {
        List<SysDept> list = service.findSysDeptByUserId(userId);
        if (list!=null){
            return Result.ok(list);
        }
        return Result.fail(list);
    }

    
}
